<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/common/common.jsp"%>

<!DOCTYPE html>
<!-- 
Template Name: Metronic - Responsive Admin Dashboard Template build with Twitter Bootstrap 3.3.6
Version: 4.5.4
Author: KeenThemes
Website: http://www.keenthemes.com/
Contact: support@keenthemes.com
Follow: www.twitter.com/keenthemes
Like: www.facebook.com/keenthemes
Purchase: http://themeforest.net/item/metronic-responsive-admin-dashboard-template/4021469?ref=keenthemes
License: You must have a valid license purchased only from themeforest(the above link) in order to legally use the theme for your project.
-->
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
    <!--<![endif]-->
    <!-- BEGIN HEAD -->

    <head>
        <meta charset="utf-8" />
        <title>后台管理系统</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta content="width=device-width, initial-scale=1" name="viewport" />
        <meta content="" name="description" />
        <meta content="" name="author" />
        <!-- BEGIN GLOBAL MANDATORY STYLES -->
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/global/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css" />
        <!-- END GLOBAL MANDATORY STYLES -->
        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <link href="${basePath}/res/assets/global/plugins/jstree/dist/themes/default/style.min.css" rel="stylesheet" type="text/css" />
        <!-- END PAGE LEVEL PLUGINS -->
        <!-- BEGIN THEME GLOBAL STYLES -->
        <link href="${basePath}/res/assets/global/css/components-rounded.min.css" rel="stylesheet" id="style_components" type="text/css" />
        <link href="${basePath}/res/assets/global/css/plugins.min.css" rel="stylesheet" type="text/css" />
        <!-- END THEME GLOBAL STYLES -->
        <!-- BEGIN THEME LAYOUT STYLES -->
        <link href="${basePath}/res/assets/layouts/layout2/css/layout.min.css" rel="stylesheet" type="text/css" />
        <link href="${basePath}/res/assets/layouts/layout2/css/themes/blue.min.css" rel="stylesheet" type="text/css" id="style_color" />
        <link href="${basePath}/res/assets/layouts/layout2/css/custom.min.css" rel="stylesheet" type="text/css" />
        <!-- END THEME LAYOUT STYLES -->
        
        <link rel="shortcut icon" href="favicon.ico" /> </head>
    <!-- END HEAD -->

    <body class="page-header-fixed page-sidebar-closed-hide-logo page-container-bg-solid">
        
        <%@ include file="/manage/page-header.jsp" %>
        
        <!-- BEGIN HEADER & CONTENT DIVIDER -->
        <div class="clearfix"> </div>
        <!-- END HEADER & CONTENT DIVIDER -->
        <!-- BEGIN CONTAINER -->
        <div class="page-container">
            
            <%@include file="/manage/page-sidebar.jsp" %>
            
            <!-- BEGIN CONTENT -->
            <div class="page-content-wrapper">
                <!-- BEGIN CONTENT BODY -->
                <div class="page-content">
                    <!-- BEGIN PAGE HEADER-->
                    
                    <%@include file="/manage/theme-panel.jsp" %>
                    <%@include file="/manage/page-title.jsp" %>
                    
                    <!-- END PAGE HEADER-->
                    <!-- BEGIN PAGE CONTENT-->
                    
                    <div class="row">
                    	<div class="col-md-12">
                    		<div class="portlet box green">
	                            <div class="portlet-title">
	                                <div class="caption">
	                                    <i class="fa fa-gift"></i>资源管理
	                                </div>
	                                <div class="actions">
										<shiro:hasPermission name="resource:add">
											<a href="javascript:doAdd();" class="btn red"><i class="fa fa-plus"></i>新增根节点</a>
										</shiro:hasPermission>                                            
                                    </div>
	                            </div>
	                            <div class="portlet-body">
                                    <ul class="list-group">
                                    
                                    	<c:forEach items="${resourceList }" var="obj">
                                    		<li class="list-group-item">
                                    			<c:forEach begin="2" end="${obj.treeLevel }">
                                    				&nbsp;&nbsp;&nbsp;&nbsp;
                                    			</c:forEach>
                                    			<label>
                                    				<c:if test="${empty obj.icon }">
					                                	<i class="icon-briefcase"></i>
					                                </c:if>
					                                <c:if test="${!empty obj.icon }">
					                                	<i class="${obj.icon }"></i>
					                                </c:if>
                                    				${obj.name }
                                    			</label>
                                    			<div class="pull-right">
                                    				<span class="badge">
                                    					<dic:getNodeName path="TOP->VISIBILITY->${obj.visibility }"></dic:getNodeName>
                                    				</span>
                                    				<div class="btn-group btn-group-sm btn-group-solid">
                                    					<shiro:hasPermission name="resource:add">
                                    						<button type="button" class="btn green-haze btn-outline sbold uppercase" onclick="doAdd('${obj.id }','${obj.name }');">新增</button>
                                    					</shiro:hasPermission>
                                    					<shiro:hasPermission name="resource:edit">
                                    						<button type="button" class="btn blue-hoki btn-outline sbold uppercase" onclick="doEdit('${obj.id }');">编辑</button>
                                    					</shiro:hasPermission>
                                    					<shiro:hasPermission name="resource:delete">
                                    						<button type="button" class="btn red-mint btn-outline sbold uppercase" onclick="doDelete('${obj.id }');">删除</button>
                                    					</shiro:hasPermission>
                                                        
                                                    </div>
                                                    
                                    			</div>
                                    		</li>
                                    	</c:forEach>
                                    
								  	</ul>
                                </div>
                            </div>
                    	</div>
                        
                    </div>
                    <!-- END PAGE CONTENT-->
                </div>
                
                <!-- END CONTENT BODY -->
            </div>
            <!-- END CONTENT -->
        </div>
        
        <div id="modelResource" class="modal fade" tabindex="-1" aria-hidden="true">
              <div class="modal-dialog">
                  <div class="modal-content">
                      <div class="modal-header">
                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                          <h4 class="modal-title" id="modelTitle"></h4>
                      </div>
                      <div class="modal-body">
                          <div class="row">
                              	<div class="col-md-2">&nbsp;</div>
                              	<div class="col-md-8">
                              		<form action="" method="post" class="form-horizontal" role="form">
                              		
                              			<input type="hidden" name="vo.id">
                              			<input type="hidden" name="vo.parentId">
                              			<div class="form-group">
                              			
						                    <label class="control-label col-md-3">父资源</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" disabled="disabled" placeholder="父资源" name="parentName"  />
						                    </div>
						                    
						                </div>
                              			<div class="form-group">
                              				
                              				<label class="control-label col-md-3"><font color="red">*</font>资源名</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="资源名" name="vo.name"  required="required"/>
						                    </div>
                              			
						                </div>
						                <div class="form-group">
						                
						                
						                	<label class="control-label col-md-3"><font color="red">*</font>资源代码</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="资源代码" name="vo.code"  required="required"/>
						                    </div>
						                
						                </div>
						                
						                <div class="form-group">
						                
						                	<label class="control-label col-md-3"><font color="red">*</font>排序</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="number" autocomplete="off" placeholder="排序" name="vo.px"  required="required"/>
						                    </div>
						                
						                </div>
						                <div class="form-group">
						                
						                	<label class="control-label col-md-3"><font color="red">*</font>可见性</label>
						                    <div class="col-md-9">
						                    	<dic:getSelect path="TOP->VISIBILITY" attributes="{name:'vo.visibility',class:'bs-select form-control'}"></dic:getSelect>
						                    </div>
						                    
						                </div>
						                <div class="form-group">
						                
						                	<label class="control-label col-md-3">URL</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="URL" name="vo.url"  />
						                    </div>
						                
						                </div>
						                <div class="form-group">
						                
						                	<label class="control-label col-md-3">图标样式</label>
						                    <div class="col-md-9">
						                    	<input class="form-control form-control-solid placeholder-no-fix" type="text" autocomplete="off" placeholder="图标样式" name="vo.icon"  />
						                    </div>
						                
						                </div>
                              		</form>
                              	</div>
                              	<div class="col-md-2">&nbsp;</div>
                              </div>
                      </div>
                      <div class="modal-footer">
                          <button type="button" data-dismiss="modal" class="btn dark btn-outline">关闭</button>
                          <button type="button" class="btn green" onclick="doSave();">保存</button>
                      </div>
                  </div>
              </div>
        </div>
            
            
        <%@ include file="/manage/page-quick-sidebar-toggler.jsp" %>
    
    	<%@ include file="/manage/page-footer.jsp" %>
            
        <!--[if lt IE 9]>
<script src="${basePath}/res/assets/global/plugins/respond.min.js"></script>
<script src="${basePath}/res/assets/global/plugins/excanvas.min.js"></script> 
<![endif]-->
        <!-- BEGIN CORE PLUGINS -->
        <script src="${basePath}/res/assets/global/plugins/jquery.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/js.cookie.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/jquery.blockui.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/uniform/jquery.uniform.min.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js" type="text/javascript"></script>
        <!-- END CORE PLUGINS -->
        
        <script src="${basePath}/res/assets/global/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
        
        <!-- BEGIN THEME GLOBAL SCRIPTS -->
        <script src="${basePath}/res/assets/global/scripts/app.js" type="text/javascript"></script>
        <!-- END THEME GLOBAL SCRIPTS -->
        <!-- BEGIN THEME LAYOUT SCRIPTS -->
        <script src="${basePath}/res/assets/layouts/layout2/scripts/layout.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/layouts/layout2/scripts/demo.js" type="text/javascript"></script>
        <script src="${basePath}/res/assets/layouts/global/scripts/quick-sidebar.min.js" type="text/javascript"></script>
        <!-- END THEME LAYOUT SCRIPTS -->
        
        <script type="text/javascript">

        	bootbox.setLocale("zh_CN");
	   	 	
	   	 	function doSave(){
	       	 	bootbox.confirm("确认保存?", function(result) {
	                if(result){
	                	$('#modelResource').find("form").submit();
	                }
	             }); 
	   	 		
	   	 	}
	   	 	
	    	function doAdd(parentId,parentName){
	    		
	    		$('#modelResource').find("form")[0].reset();
	    		
	    		if(parentId){
	    			$(":input[name='vo.parentId']").val(parentId);
	    			$(":input[name='parentName']").val(parentName);
	    		}else{
	    			$(":input[name='vo.parentId']").val();
	    			$(":input[name='parentName']").val();
	    		}
	    		$("#modelTitle").html("资源新增");
	    		$('#modelResource').modal({});
	    		$('#modelResource').find("form").attr("action","${basePath}/manage/resource/add/");
	    	}
	    	
			function doEdit(id){
				$('#modelResource').find("form")[0].reset();
				
    			$.ajax({
    				type:"post",
    				url:"${basePath}/manage/resource/viewJson/",
    				data:"id="+id,
    				success:function(data){
    					if(data.flag){
    						var map=data.data;
    						var resource=map.resource;
    						var resourceParent=map.resourceParent;
    						if(resourceParent){
    							$(":input[name='vo.parentId']").val(resourceParent.id);
        		    			$(":input[name='parentName']").val(resourceParent.name);
    						}
    						for(var i in resource){
    							$(":input[name='vo."+i+"']").val(resource[i]);
    						}
    					}
    					
    				}
    			});
    			
				$("#modelTitle").html("资源编辑");
				$('#modelResource').modal({});
				$('#modelResource').find("form").attr("action","${basePath}/manage/resource/edit/");
	    	}
        
			function doDelete(id){
				bootbox.confirm("确认删除?同时会删除所有子节点。", function(result) {
	               if(result){
	            	  window.location.href='${basePath}/manage/resource/delete/?id='+id; 
	               }
	            }); 
				
			}
			
        </script>
        
    </body>

</html>